In Rust, pattern matching is not just a branch of control flow—it is the very architecture of binding. Every time you declare a variable or define a function, you are engaging in pattern matching.
1. The Identity of Binding
When we write let x = 5;, we aren't just assigning a value. We are matching the value 5 against the irrefutable pattern x. Because x is a name that can represent any value, the match always succeeds and creates a local binding.
2. Patterned Parameters (Listing 18-6)
Perhaps the most profound realization is that function signatures are patterns. In the signature fn foo(x: i32), the code expects an i32 and uses the pattern x to bind the incoming argument. This means every function entry is essentially a single-arm match event.
3. Ubiquity of Patterns
Patterns extend beyond match. They appear in for loops (destructuring tuples), while let conditionals, and even if let expressions. This Local Binding principle ensures that Rust code is consistently expressive, whether you are extracting data from a struct or iterating over a hashmap.